﻿using UnityEngine;
using System.Collections;

public class Ampuminen : MonoBehaviour {

	public GameObject ammus;
	public static int ammuksia = 0;
	
	void Update () {

		// ampuminen
		if(Input.GetKeyDown(KeyCode.AltGr) && ammuksia > 0) 
		{
			// luodaan uusi instanssi ammuksen gameobjectista
			GameObject clone = Instantiate(ammus, transform.position, transform.rotation)as GameObject;

			if(transform.parent.transform.localScale.x > 0)
				clone.rigidbody2D.velocity = -transform.parent.transform.right * 10f;
			else
				clone.rigidbody2D.velocity = transform.parent.transform.right * 10f;

			// vähennetään ammuksia
			ammuksia--;
		}
	}
}
